app.service('GoodsSkuService',['$http','$q','utilService',function($http,$q,utilService){
    var _this_=this;

    _this_.sku=new Object();

    _this_.addSku=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'chain/sku',
            data:_this_.sku
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }

    _this_.addSkuItems=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'chain/sku/items',
            data:_this_.skuItems
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }

    _this_.getSkuAll= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'chain/sku/all'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }


    _this_.getSkuItemsAll=function($scope,id){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'chain/sku/items/all',
            params:{skuId:id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }


    //获取商品相关SKU名称和规格
    _this_.queryGoodsSkuItems= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'chain/goodssku/skuitems/bo/'+$scope.goodsId
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }


    //获取商品相关SKU名称和规格
    _this_.querySkuContent= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'chain/goodssku/skucontent/'+$scope.goodsId
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }

}])